package com.aliyun.heiyu.powermaster.server;

import com.aliyun.heiyu.powermaster.server.agent.AgentManager;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class PowerMasterServer {

    private static Logger log = LoggerFactory.getLogger(PowerMasterServer.class);

    public static void main(String[] args) throws IOException, InterruptedException, Exception {

        ServerInterceptor serverInterceptor = new ServerInterceptor();

        AgentManager agentManager = new AgentManager();

        Options options = new Options();
        options.addOption("h", "help", false, "Print this usage information");
        options.addOption("v", "verbose", false, "Print out VERBOSE information");
        options.addOption("m", "market", false, "Enable marketing for hibenating strategy");

        CommandLineParser parser = new BasicParser();
        CommandLine commandLine = parser.parse(options, args);

        if (commandLine.hasOption('m')) {
        }


        AgentServiceImpl agentService = new AgentServiceImpl(agentManager);
        PowerMasterServiceImpl powermasterService = new PowerMasterServiceImpl();

        int port = 30031;
        Server server = ServerBuilder.forPort(port).intercept(serverInterceptor).addService(agentService).addService(powermasterService).build()
            .start();
        log.info("PowerMaster Server started, listening on " + port);
        server.awaitTermination();
    }

}
